//
//  ZMKitMacros.h
//  ZMKitDemo
//
//  Created by zm on 2018/6/13.
//  Copyright © 2018年 zm. All rights reserved.
//

#ifndef ZMKitMacros_h
#define ZMKitMacros_h

#ifndef dispatch_queue_async_safe
#define dispatch_queue_async_safe(queue, block)\
if (strcmp(dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL), dispatch_queue_get_label(queue)) == 0) {\
block();\
} else {\
dispatch_async(queue, block);\
}
#endif

#ifndef dispatch_main_async_safe
#define dispatch_main_async_safe(block) dispatch_queue_async_safe(dispatch_get_main_queue(), block)
#endif


#define weakify(o)     \
autoreleasepool {} \
__weak typeof(o) o##weak = o;
#define strongify(o)   \
autoreleasepool {} \
__strong typeof(o) o = o##weak;


#define SYSTEM_VERSION_EQUAL_TO(v)                  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v)              ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v)                 ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v)     ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)

#define SCREEN_WIDTH ([[UIScreen mainScreen]bounds].size.width)
#define SCREEN_HEIGHT ([[UIScreen mainScreen]bounds].size.height)
#define STATUS_HEIGHT [[UIApplication sharedApplication] statusBarFrame].size.height
#define SCREEN_WITHOUT_STATUS_HEIGHT (SCREEN_HEIGHT - STATUS_HEIGHT)
#define NAV_HEIGHT (44.0)
#define TOP_HEIGHT  (STATUS_HEIGHT + NAV_HEIGHT)
#define TAB_SAFE_BOTTOM_MARGIN (IS_IPHONE_X ? 34.f : 0.f)
#define TABBAR_HEIGHT (49.0)
#define BOTTOM_HEIGHT (TAB_SAFE_BOTTOM_MARGIN + 49.0)

#define IS_IPHONE_X (SCREEN_WIDTH == 375.f && SCREEN_HEIGHT == 812.f)

#define kHPercentage(a) (SCREEN_HEIGHT*((a)/667.00))
#define kWPercentage(a) (SCREEN_WIDTH *((a)/375.00))


#define UIColorFromRGB(rgbValue)            [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1]

#define UIColorFromRGBWithAlpha(rgbValue,alphaValue)            [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:alphaValue]


#endif /* ZMKitMacros_h */
